<template>
  <transition name="fade-zoom">
    <div class="vote-menu" :class="{pc:pcClass}">
      <div class="vote-menu-top">
        <div class="vote-menu-img-box zoomIn" v-if="showQrCode" key="1">
          <img :src="qrCodeUrl" alt="">
        </div>
        <div class="vote-menu-img-box zoomIn" v-if="showWx" key="2">
          <img :src="wxUrl" alt="">
        </div>
        <div class="vote-menu-img-box zoomIn" v-if="showProgram" key="3">
          <img :src="programUrl" alt="">
        </div>
      </div>
      <div class="menu" v-if="onlyService">
        <div class="menu-item-box" :class="{'around': onlyService}">
          <div class="menu-item zoomIn" @click="onQQ" v-if="qq">
            <div class="menu-icon"><img src="../assets/img/menu-qq.png" alt=""></div>
            <div class="menu-name">QQ客服</div>
          </div>
          <div class="menu-item zoomIn" @click.prevent="onShowWx" v-if="wxqr">
            <div class="menu-icon"><img src="../assets/img/menu-weixin.png" alt=""></div>
            <div class="menu-name">微信客服</div>
          </div>
          <div class="menu-item zoomIn" @click="onTel">
            <div class="menu-icon"><img src="../assets/img/menu-tel.png" alt=""></div>
            <div class="menu-name">客服电话</div>
          </div>
        </div>
        <div class="menu-item-box">
          <div class="menu-item zoomIn"></div>
          <div class="menu-item zoomIn" @click="onClose">
            <div class="menu-close">
              <img src="../assets/img/close-btn.png" alt="">
            </div>
          </div>
          <div class="menu-item zoomIn"></div>
        </div>
      </div>
      <!-- 3个或2个 显示 -->
      <div class="menu" v-else-if="showTwoOrThree">
        <div class="menu-item-box">
          <div class="menu-item zoomIn" @click.prevent="onShowProgram" v-if="AppletLink">
            <div class="menu-icon"><img src="../assets/img/menu-program.png" alt=""></div>
            <div class="menu-name">小程序码</div>
          </div>
          <div class="menu-item zoomIn" @click="onShowQrcode">
            <div class="menu-icon"><img src="../assets/img/menu-code.png" alt=""></div>
            <div class="menu-name">页面二维码</div>
          </div>
          <div class="menu-item zoomIn" @click.prevent="onShowWx" v-if="wxqr">
            <div class="menu-icon"><img src="../assets/img/menu-weixin.png" alt=""></div>
            <div class="menu-name">微信客服</div>
          </div>
          <div class="menu-item zoomIn" @click="onQQ" v-if="qq">
            <div class="menu-icon"><img src="../assets/img/menu-qq.png" alt=""></div>
            <div class="menu-name">QQ客服</div>
          </div>
        </div>
        <div class="menu-item-box">
          <div class="menu-item zoomIn" @click.prevent="onRecomand">
            <div class="menu-icon"><img src="../assets/img/menu-recomand.png" alt=""></div>
            <div class="menu-name">品牌推荐</div>
          </div>
          <div class="menu-item zoomIn" @click="onClose">
            <div class="menu-close">
              <img src="../assets/img/close-btn.png" alt="">
            </div>
          </div>
          <div class="menu-item zoomIn" @click.prevent="onTel">
            <div class="menu-icon"><img src="../assets/img/menu-tel.png" alt=""></div>
            <div class="menu-name">客服电话</div>
          </div>
        </div>
      </div>
      <!-- 1个 显示 -->
      <div class="menu" v-else>
        <div class="menu-item-box">
          <div class="menu-item zoomIn" @click.prevent="onShowProgram" v-if="AppletLink">
            <div class="menu-icon"><img src="../assets/img/menu-program.png" alt=""></div>
            <div class="menu-name">小程序码</div>
          </div>
          <div class="menu-item zoomIn" @click="onShowQrcode">
            <div class="menu-icon"><img src="../assets/img/menu-code.png" alt=""></div>
            <div class="menu-name">页面二维码</div>
          </div>
          <div class="menu-item zoomIn" @click.prevent="onRecomand">
            <div class="menu-icon"><img src="../assets/img/menu-recomand.png" alt=""></div>
            <div class="menu-name">品牌推荐</div>
          </div>
          <div class="menu-item zoomIn" @click.prevent="onShowWx" v-if="wxqr">
            <div class="menu-icon"><img src="../assets/img/menu-weixin.png" alt=""></div>
            <div class="menu-name">微信客服</div>
          </div>
          <div class="menu-item zoomIn" @click="onQQ" v-if="qq">
            <div class="menu-icon"><img src="../assets/img/menu-qq.png" alt=""></div>
            <div class="menu-name">QQ客服</div>
          </div>
          <div class="menu-item zoomIn" @click.prevent="onTel">
            <div class="menu-icon"><img src="../assets/img/menu-tel.png" alt=""></div>
            <div class="menu-name">客服电话</div>
          </div>
        </div>
        <div class="menu-item-box menu-item-center">
          <div class="menu-item zoomIn" @click="onClose">
            <div class="menu-close">
              <img src="../assets/img/close-btn.png" alt="">
            </div>
          </div>
        </div>
      </div>
      <vodal :show="phoneshow" animation="zoom" measure="rem" :width="6" :height="3.52" :closeButton="false">
        <div class="vodal-box">
          <div class="title">
            <h6>客服电话</h6>
            <p>品牌中网客服电话为：</p>
            <p class="tel">{{tel}}</p>
          </div>
          <div class="close" @click="phoneshow = false">我知道了</div>
        </div>
      </vodal>
    </div>
  </transition>
</template>

<script>
import { mapState } from 'vuex'
import scroll from '../mixins/scroll'
import consts from '../common/consts'
import {
  accessLog
} from '../common/dataBuried'
export default {
  mixins: [scroll],
  props: {
    onlyService: { // 在添加品牌页 和 申请奖杯页为true 其他为false
      type: Boolean,
      default: false
    },
    cstatus: {
      type: Number
    }
  },
  data() {
    return {
      qrCodeUrl: '',
      showQrCode: false,
      wxUrl: '',
      showWx: false,
      programUrl: '',
      showProgram: false,
      pcClass: false,
      phoneshow: false
    }
  },
  computed: {
    ...mapState({
      catName: s => s.catName,
      wxqr: s => s.serviceInfo.wxqr,
      qq: s => s.serviceInfo.qq,
      tel: s => s.serviceInfo.tel,
      voteLink: s => s.wxVoteLink,
      AppletLink: s => s.wxAppletLink
    }),
    showTwoOrThree() {
      if ((this.AppletLink && this.qq && this.wxqr) || (this.AppletLink && this.qq) || (this.AppletLink && this.wxqr) || (this.qq && this.wxqr)) {
        return true
      }
    }
  },
  mounted() {
    if (!this.$getDeviceInfo().isPhone && document.documentElement.getBoundingClientRect().width > 560) {
      this.pcClass = true
    }
  },
  methods: {
    onClose() {
      this.$emit('closeMenu')
      this.showWx = false
      this.showQrCode = false
      this.showProgram = false

    },
    // qq客服
    onQQ() {
      window.location.href =
        'http://wpa.qq.com/msgrd?v=3&uin=' +
        this.qq +
        '&site=qq&menu=yes'
    },
    // 品牌推荐
    onRecomand() {
      this.scroll(true)
      this.$router.push('/addbrand?catid=' + this.$route.query.catid + '&from=voteMenu&formPath=' + this.$route.path)
    },
    // 页面二维码
    onShowQrcode() {
      this.showWx = false
      this.showProgram = false
      if (!this.showQrCode) {
        this.qrCodeUrl = this.voteLink
        this.showQrCode = true
      } else {
        this.showQrCode = false
      }
      if (this.cstatus === 0) {
        this.cstatus = 7
      }
      accessLog('etck3', this.cstatus)
    },
    // 微信客服
    onShowWx() {
      this.showQrCode = false
      this.showProgram = false
      if (!this.showWx) {
        let url = encodeURIComponent(this.wxqr)
        url += '&catname=' + this.catName
        this.wxUrl = 'http://' + consts.domain + '/api/api_qrcode_wechat.php?url=' + url
        this.showWx = true
      } else {
        this.showWx = false
      }
    },
    // 小程序码
    onShowProgram() {
      this.showWx = false
      this.showQrCode = false
      if (!this.showProgram) {
        this.programUrl = this.AppletLink
        this.showProgram = true
      } else {
        this.showProgram = false
      }
      if (this.cstatus === 0) {
        this.cstatus = 7
      }
      accessLog('zweli', this.cstatus)
    },
    // 客服电话
    onTel() {
      // 关闭 页面二维码 微信客服
      this.showWx = false
      this.showQrCode = false
      if (this.$getDeviceInfo().isPhone) {
        window.location.href = 'tel:' + this.tel
      } else {
        this.phoneshow = true
      }
    }
  }
}
</script>
<style lang="scss">
.fade-zoom-enter-active {
  transition: opacity 0.5s;
}
.fade-zoom-enter,
.fade-zoom-leave-to {
  opacity: 0;
}
.fade-zoom-leave-active {
  transition: none;
}
@keyframes zoomIn {
  from {
    opacity: 0;
    transform: scale3d(0.3, 0.3, 0.3);
  }

  50% {
    opacity: 1;
  }
}

.zoomIn {
  animation-name: zoomIn;
}
</style>

<style scoped lang="scss">
.vote-menu {
  width: 100%;
  height: 100%;
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background-color: rgba(255, 255, 255, 0.9);
  z-index: 2;
  &.pc {
    width: 560px;
    left: 50%;
    transform: translate3d(-280px, 0, 0);
  }
  .menu {
    position: absolute;
    width: 100%;
    height: 3.9rem;
    left: 0;
    bottom: 0;
    margin-bottom: 0.2rem;
    .menu-item-box {
      padding: 0 0.75rem;
      display: flex;
      justify-content: space-between;
    }
    .around {
      justify-content: space-around;
    }
    .menu-item-center {
      justify-content: center;
    }
    .menu-item {
      // min-width: 25%;
      text-align: center;
      margin-bottom: 0.45rem;
      animation-duration: 1s;
      animation-fill-mode: both;
    }
    .menu-icon {
      width: 0.9rem;
      height: 1.1rem;
      margin: auto;
      img {
        width: 100%;
        height: auto;
        box-shadow: 0.01rem 0.04rem 0.08rem 0 rgba(51, 51, 51, 0.2);
        border-radius: 50%;
      }
    }
    .menu-name {
      font-size: 0.22rem;
      line-height: 0.24rem;
      color: #444;
    }
  }
  .menu-close {
    width: 0.32rem;
    height: 0.32rem;
    margin: 0.5rem auto;
    img {
      width: 100%;
      height: auto;
    }
  }
  .vote-menu-img-box {
    width: 100%;
    padding: 0.75rem;
    animation-duration: 0.5s;
    animation-fill-mode: both;
    img {
      width: 100%;
      height: auto;
    }
  }
  .vodal-box {
    text-align: center;
    padding-top: 0.56rem;
    .title {
      h6 {
        font-size: 0.32rem;
        line-height: 0.32rem;
        color: #333;
        &::after {
          content: "";
          width: 1.2rem;
          height: 1px;
          background: #dfdfdf;
          display: inline-block;
          vertical-align: middle;
          margin-left: 0.4rem;
        }
        &::before {
          content: "";
          width: 1.2rem;
          height: 1px;
          background: #dfdfdf;
          display: inline-block;
          vertical-align: middle;
          margin-right: 0.4rem;
        }
      }
      p {
        margin-top: 0.52rem;
        font-size: 0.26rem;
        line-height: 0.26rem;
        color: #999;
      }
      .tel {
        margin-top: 0.2rem;
        font-size: 0.36rem;
        line-height: 0.36rem;
        color: #333;
      }
    }
    .close {
      position: absolute;
      bottom: 0;
      left: 0;
      right: 0;
      width: 100%;
      border-top: 1px solid rgba(204, 204, 204, 1);
      line-height: 0.86rem;
      font-size: 0.3rem;
      color: #333;
      cursor: pointer;
    }
  }
}
</style>
